package com.leo;

import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.core.util.LazyValue;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.SpawnData;
import com.leo.entity.SubSceneEntityFactory;
import com.leo.ui.CustomSubScene;
import javafx.scene.Node;

/**
 * @Author: wangss
 * @CreateTime: 2023-06-18  05:26
 * @Description: TODO
 */
public class SubSceneApp extends GameApplication {

    // 懒加载
    private LazyValue<CustomSubScene> subSceneLazyValue = new LazyValue<>(() -> new CustomSubScene());

    @Override
    protected void initSettings(GameSettings settings) {

    }

    @Override
    protected void initGame() {
        FXGL.getGameWorld().addEntityFactory(new SubSceneEntityFactory());
        Entity rect = FXGL.spawn("rect", new SpawnData(20, 20));
        Node node = rect.getViewComponent().getChildren().get(0);
        node.setOnMouseClicked(event -> {
            FXGL.getSceneService().pushSubScene(subSceneLazyValue.get());
        });
    }

    public static void main(String[] args) {
        launch(args);
    }
}
